package com.example.jetpacktest.databinding;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.example.jetpacktest.R;

public class DataBindingExampleActivity extends AppCompatActivity {
    String inputText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final ActivityDataBindingExampleBinding databinding = DataBindingUtil.setContentView(this, R.layout.activity_data_binding_example);
        databinding.setUserInfo(new UserInfo("张三", 1, "中国"));
        databinding.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(DataBindingExampleActivity.this, "点击了name", Toast.LENGTH_SHORT).show();
                Log.e("!!!!!!!!!!", "" + databinding.getInputText());
            }
        });
        databinding.setOnClickHandle(new OnClickHandle(DataBindingExampleActivity.this));
        databinding.setImageres(R.mipmap.ic_launcher_round);
        databinding.setInputText(inputText);

        databinding.setInputViewModel(new InputObservable("默认"));

        InputObservableField field = new InputObservableField();
        field.name.set("123");
        databinding.setInputField(field);
    }

    public class OnClickHandle {
        private Context context;

        public OnClickHandle(Context context) {
            this.context = context;
        }

        public void onClick(View view) {
            Toast.makeText(context, "点击了", Toast.LENGTH_SHORT).show();
        }
    }
}